Skip to content

the task #2 from HW #2 was completed - #3

Open
Dmitriy-Klv wants to merge 3 commits into
samodurOFF:masterfrom
Dmitriy-Klv:task/pydantic-validation_hm2
Open

the task #2 from HW #2 was completed#3
Dmitriy-Klv wants to merge 3 commits into
samodurOFF:masterfrom
Dmitriy-Klv:task/pydantic-validation_hm2

Conversation

@Dmitriy-Klv

Copy link
Copy Markdown

No description provided.

@samodurOFF samodurOFF left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исправьте и можно мержить

Comment thread HWs/DmitriyK/HM2/main.py
from pydantic import BaseModel, EmailStr, Field, model_validator

class Address(BaseModel):
city: str = Field(..., min_length=2)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

С версии 2.0 в pydantic не нужно указывать ... для обозначения обязательного поля, о чем я говорил на занятии.

Suggested change
city: str = Field(..., min_length=2)
city: str = Field(min_length=2)

Comment thread HWs/DmitriyK/HM2/main.py
Comment on lines +18 to +19
if self.is_employed:
if not (18 <= self.age <= 65):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше перечислить эти условия через and

Suggested change
if self.is_employed:
if not (18 <= self.age <= 65):
if self.is_employed and not (18 <= self.age <= 65):

Comment thread HWs/DmitriyK/HM2/main.py
user = User.model_validate_json(json_str)
return user.model_dump_json(indent=4)
except pydantic.ValidationError as e:
return f"Validation error: {e.json()}"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не очень хорошо, когда функция возвращает различные структуры данных.

Suggested change
return f"Validation error: {e.json()}"
return e.json()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants